package com.youdianstar.app.ui

import com.youdianstar.app.R
import com.youdianstar.app.BR
import com.youdianstar.app.databinding.ActivityReportResultBinding
import com.youdianstar.app.common.BisType
import com.youdianstar.app.common.Extra
import com.youdianstar.app.common.base.BaseActivity
import com.youdianstar.app.util.DataAppManager
import com.youdianstar.app.common.util.MathUtil

import com.youdianstar.app.common.auko.startActivity
import org.koin.androidx.viewmodel.ext.android.viewModel


/**
 * File: ReportResultActivity
 * Author: 82149 Create: 2021/11/19 10:55
 * Changes (from 2021/11/19)
 * --------------------------------------------------
 * description:
 * ---------------------------------------------------
 *
 */
class ReportResultActivity : BaseActivity<ActivityReportResultBinding, ReportViewModel>() {
    override fun layoutId(): Int = R.layout.activity_report_result

    override fun initVariableId(): Int = BR.viewModel

    override fun initViewModel(): ReportViewModel {
        val model: ReportViewModel by viewModel()
        return model
    }

    private var bisType = 0
    private var penaltyAmount = 0.0F

    override fun initData() {
        super.initData()
        mBinding.headBar.initTitle(this, title = "", showInner = false)
        mBinding.headBar.setBackUnable()

        bisType = intent.getIntExtra(Extra.IT_TYPE, BisType.Report_Feedback)

        mBinding.ivResult.setImageResource(R.mipmap.ic_order_rp_success)

        when (bisType) {
            BisType.Report_Feedback -> {
                mBinding.resultTitle.text = getString(R.string.help_submitted)
                mBinding.resultContent.text = getString(R.string.help_thankText)
                mBinding.btnHome.text = getString(R.string.order_homePage)
            }

            BisType.Report_OrderFault -> {
                mBinding.resultTitle.text = getString(R.string.help_submitted)
                mBinding.resultContent.text =  getString(R.string.help_thankText)
                mBinding.btnHome.text = getString(R.string.order_homePage)
            }
            else -> {
                mBinding.resultTitle.text = getString(R.string.help_submitted)
                penaltyAmount = intent.getFloatExtra(Extra.IT_MONEY,0F)

                val symbolStr = DataAppManager.instance.symbolTx()
                val penaltyStr = symbolStr+MathUtil.round(penaltyAmount)

                val notifyPart = String.format(getString(R.string.help_orderFBText), penaltyStr)
                mBinding.resultContent.text = notifyPart
                mBinding.btnHome.text = getString(R.string.order_homePage)
            }
        }
    }

    override fun initClickEvent() {
        mBinding.btnHome.setOnClickListener {
            actionHome()
        }
    }

    private fun actionHome() {
        if (bisType != BisType.Report_Feedback) {
            startActivity<MainActivity>()
        }
        finish()
    }

    override fun onBackPressed() {
        super.onBackPressed()
        actionHome()
    }

}